/*
 * Log.cpp
 *
 *  Created on: 26.02.2012
 *      Author: caffeine
 */

#include "Log.h"
namespace irr{
namespace log{

LogFunction callback=0;
void*self;

irr::ELOG_LEVEL Log::stringToLogLevel(irr::core::stringc a){
	irr::ELOG_LEVEL res=ELL_INFORMATION;
	if (a=="info" || a=="i")
		res=irr::ELL_INFORMATION;

	if (a=="error" || a=="e")
		res=irr::ELL_ERROR;

	if (a=="warning" || a=="w")
		res=irr::ELL_WARNING;
	if (a=="none" || a=="n")
		res=irr::ELL_NONE;
	return res;
}

void Log::add(irr::thread::ThreadID current_chread,char*text,irr::ELOG_LEVEL level,const char*filename,const char*function,irr::u32 line){
	if (callback==0){
		fprintf(stdout,"%s %s:%d  %s\n",filename,function,line,text);
		return;
	}
	callback(current_chread,text,level,filename,function,line,self);
	//printf(stdout,"%s:%d  %s\n",function,line,text);
}

void Log::add(irr::thread::ThreadID current_chread,irr::core::stringc text,irr::ELOG_LEVEL level,const char*filename,const char*function,irr::u32 line){
	add(current_chread,(char*)text.c_str(),level,filename,function,line);
}

void Log::setReceiver(LogFunction fun,void*sender){
	callback=fun;
	self=sender;
}
}//namespace log
}//namespace irr
